/*
 * Copyright 2010-2012 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.code.newpath.core;

import com.google.code.newpath.core.exception.PathException;


/**
 * API for accessing resouce instance that
 * are currently associated with a particular lifecycle scope.
 * 
 * @author Charlie Zhang
 */
public interface Context {
	
	public ResourceFactory getResourceFactory();
	
	/**
	 * Change the current directory to dir.
	 * @param path
	 * @throws PathException
	 */
	public void setWorkingDirectory(Path path) throws PathException;
	
	/**
	 * retrun the path of the current working directory.
	 * 
	 * @return
	 */
	public Path getWorkingDirectory();
	
	
	/**
	 * Context has hierarchical relationship, this method return parent hierarchical one.
	 * If this class is root of hierarchy, it will return null. 
	 * @return 
	 */
	public Context getParent();
	
	/**
	 * Get target by path.
	 * The corresponding target object will be cached after first invoke this method by corresponding path. 
	 * Equals to invoke method: getTarget(path, true, false)
	 */
	public Object getTarget(Path path);
	
	public Object getTarget(String path);
	
	/**
	 * Get target by path. If setWorkingDirectory is true, setWorkingDirectory() method will be invoked and <br/>
	 *  the Working Directory will be set as path.getParent().
	 * @param path
	 * @param setWorkingDirectory
	 * @param thisScope get target only for this scope.  If thisScope is false, it will search target in parent context. 
	 * @return
	 */
	public Object getTarget(Path path, boolean setWorkingDirectory, boolean thisScope);
	
	public Object getTarget(String path, boolean setWorkingDirectory, boolean thisScope);
	

	/**
	 * Get the scope that this context object is associated with,
	 */
	public String getScope();
	
	/**
	 * Flush the all match target which was cached in current context.
	 * And the additional operation is these all match targets will be call destroy method before it be remove from the cache.
	 * 
	 * If matchPattern is null, all cached target will be removed!  
	 * 
	 * @param mathPattern
	 */
	public void flush(PathMatchPattern matchPattern);
	
	

}
